package com.bzg.baseSpringComponent.typeConverter;

import org.springframework.beans.factory.config.CustomEditorConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ConversionServiceFactoryBean;

import java.util.Collections;
import java.util.HashMap;

public class Config {

	// 将属性编辑器注入spring
	@Bean
	public CustomEditorConfigurer customEditorConfigurer() {
		CustomEditorConfigurer customEditorConfigurer = new CustomEditorConfigurer();
		HashMap hashMap = new HashMap();
		hashMap.put(User.class,StringToUserPropertyEditor.class);
		customEditorConfigurer.setCustomEditors(hashMap);
		return customEditorConfigurer;
	}

	// 将converter器注入spring
	@Bean
	public ConversionServiceFactoryBean conversionServiceFactoryBean() {
		ConversionServiceFactoryBean conversionServiceFactoryBean = new ConversionServiceFactoryBean();
		conversionServiceFactoryBean.setConverters(Collections.singleton(new StringToUserConverter()));
		return conversionServiceFactoryBean;
	}
}
